<template>
	<view class="cart-container" v-if="cart.length !== 0">
    <!-- 收货地址 -->
    <my-address></my-address>
    
		<!-- 标题 -->
    <view class="cart-title">
      <uni-icons type="shop" size="18"></uni-icons>
      <text class="cart-title-text">购物车</text>
    </view>
    <!-- 模块组件 -->
    <!-- 滑动删除 -->
    <uni-swipe-action>
      <block v-for="(item,i) in cart" :key="i">
        <uni-swipe-action-item :options="options" @click="swipeActionClickHandler(item)">
        <my-goods :goods="item" :showNum="true" :showRadio="true" @radio-change="radioChangeHandler" @num-change="numChangeHandler"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 底部bar 结算区 -->
    <my-settle></my-settle>

    
	</view>
      <!-- 空购物车时展示 -->
  <view class="empty-cart" v-else>
    <image class="empty-img" src="/static/cart_empty@2x.png" mode=""></image>
    <text class="tip-text">空空如也~</text>
  </view>    
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
	import {mapState,mapMutations} from 'vuex'
  export default {
    mixins:[badgeMix],
    computed:{
      ...mapState('m_cart',['cart']),
      
    },
		data() {
			return {
        // 向左滑动删除
				options:[{
          text:'删除',
          style:{
            backgroundColor:'#c00000'
          }
        }],
          
			};
		},
    methods:{
      ...mapMutations('m_cart',['undataGoodsNum','undataGoodsState','removeGoodsById']),
      // 点击切换选中状态
      radioChangeHandler(e){
        
        this.undataGoodsState(e)
      },
      // 点击增加或减少数量
      numChangeHandler(e){
        // console.log(e);
        this.undataGoodsNum(e)
      },
      // 滑动删除按钮点击
      swipeActionClickHandler(goods){
        console.log(goods);
        this.removeGoodsById(goods.goods_id)
      },
      // 
    }
	}
</script>

<style lang="scss">
  // 底部上浮
  .cart-container{
    padding-bottom: 50px;
  }
// 购物车标题
.cart-title{
  height: 40px;
  display: flex;
  align-items: center;
  font-size: 14px;
  padding-left: 5px;
  border-bottom: 1px solid #efefef;
  // 文本
  .cart-title-text{
    margin-left: 10px;
  }
}
// 购物车为空时展示
.empty-cart{
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding-top: 150px;
  .empty-img{
    width: 90px;
    height: 90px;
  }
  .tip-text{
    font-size: 12;
    color: grap;
    margin-top: 15px;
  }
}
</style>
